package com.example.bbs.bean;

import android.os.Parcel;
import android.os.Parcelable;

@SuppressWarnings("unused")
public class Post implements Parcelable {

    public static final int TYPE_NORMAL = 0;
    public static final int TYPE_DRAFT = 1;
    public static final int TYPE_DELETED = 2;
    public static final int STYLE_ALL = 0b1111;
    public static final int STYLE_TEXT_ONLY = 1;
    public static final int STYLE_IMAGE = 1 << 1;
    public static final int STYLE_AUDIO = 1 << 2;
    public static final int STYLE_VIDEO = 1 << 3;

    public static String EMPTY = "Empty Error";
    public static String DEFAULT_TITLE = "随记";

    private int id;
    private String title;
    private String abstractContent;
    private String content;
    private int type;
    private int style = -1;
    private String location;
    private int authorId;
    private int likeNum;
    private boolean likeOr;

    public Post() {
        this(EMPTY, "", "", -1, STYLE_TEXT_ONLY, "");
    }

    public Post(String title, String content, String abstractContent, int authorId, int style, String location) {
        this(-1,
                title == null || title.isEmpty() ? DEFAULT_TITLE : title,
                abstractContent,
                content,
                authorId,
                TYPE_NORMAL,
                style,
                location,
                0,
                false
        );
    }

    public Post(int id, String title, String abstractContent, String content, int authorId, int type,
                int style, String location, int likeNum, boolean likeOr) {
        this.id = id;
        this.title = title;
        this.abstractContent = abstractContent;
        this.content = content;
        this.authorId = authorId;
        this.type = type;
        this.style = style;
        this.location = location;
        this.likeNum = likeNum;
        this.likeOr = likeOr;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAbstractContent() {
        return abstractContent;
    }

    public void setAbstractContent(String abstractContent) {
        this.abstractContent = abstractContent;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getStyle() {
        return style;
    }

    public void setStyle(int style) {
        this.style = style;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public int getAuthorId() {
        return authorId;
    }

    public void setAuthorId(int authorId) {
        this.authorId = authorId;
    }

    public int getLikeNum() {
        return likeNum;
    }

    public void setLikeNum(int likeNum) {
        this.likeNum = likeNum;
    }

    public boolean isLikeOr() {
        return likeOr;
    }

    public void setLikeOr(boolean likeOr) {
        this.likeOr = likeOr;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(title);
        dest.writeString(abstractContent);
        dest.writeString(content);
        dest.writeInt(authorId);
        dest.writeInt(type);
        dest.writeInt(style);
        dest.writeString(location);
        dest.writeInt(likeNum);
        dest.writeInt(likeOr ? 1 : 0);
    }

    public static final Creator<Post> CREATOR = new Creator<Post>() {
        @Override
        public Post createFromParcel(Parcel source) {
            return new Post(
                    source.readInt(),                       // id
                    source.readString(),                    // title
                    source.readString(),                    // abstractContent
                    source.readString(),                    // content
                    source.readInt(),                       // authorId
                    source.readInt(),                       // type
                    source.readInt(),                       // style
                    source.readString(),                    // location
                    source.readInt(),                       // likeNum
                    source.readInt() > 0              // likeOr
            );
        }

        @Override
        public Post[] newArray(int size) {
            return new Post[size];
        }
    };
}
